import EventManage from "./Framework/Managers/EventManage";
import { NetManage } from "./Framework/Managers/NetManage";
import ResManage from "./Framework/Managers/ResManage";
import SoundManage from "./Framework/Managers/SoundManage";
import TableManage from "./Framework/Managers/TableManage";
import TimerManage from "./Framework/Managers/TimerManage";
import UIManage from "./Framework/Managers/UIManage/UIManage";
import GameApplication from "./GameCentre/GameApplication";
import { AuthProxy } from "./ServerProxy/Proxy/AuthProxy";
import { TcpClient } from "./ServerProxy/TcpClient";



const { ccclass, property } = cc._decorator;

@ccclass
export default class GameLanch extends cc.Component {

    //网络部分
    @property({ tooltip: "是否使用网络模块" })
    m_useNet: boolean = false;

    @property({
        visible() { return this.m_useNet }
    })
    m_serveUrl: string = 'ws://127.0.0.1:8080';


    //物理部分
    @property({ tooltip: "是否开启物理引擎" })
    m_usePhy: boolean = false;

    @property({
        tooltip: "是否调试模式",
        visible() { return this.m_usePhy }
    })
    m_isDebug: boolean = false;

    @property({
        tooltip: "重力加速度",
        visible() { return this.m_usePhy }
    })
    m_gravity: cc.Vec2 = cc.v2(0, -320);

    onLoad() {
        console.log('Game Lanching......');
        // 1、初始化框架逻辑
        this.node.addComponent(UIManage);
        this.node.addComponent(ResManage);
        this.node.addComponent(SoundManage);
        this.node.addComponent(EventManage);
        this.node.addComponent(TimerManage);
        this.node.addComponent(TableManage);

        if (this.m_useNet) {
            TcpClient.Instance.init();
            AuthProxy.Instance.init();
            //... ...
            this.node.addComponent(NetManage).init(this.m_serveUrl);
        }

        // 2、启动游戏管理
        this.node.addComponent(GameApplication).initPhy(this.m_usePhy, this.m_isDebug, this.m_gravity);
    }

    start() {
        GameApplication.Instance.EnterGame();
    }
}
